<template>
	<view>
		<view class=" u-p-r-30 u-p-l-30 u-m-t-20" >
			<view class="content wrap">
				<u-form>
					<u-form-item label="日期" label-width="170" left-icon="calendar"><u-input v-model="times" placeholder="选择日期" type="select" @click="getT()"/></u-form-item>
				</u-form>
			</view>
		</view>
		<u-card padding="16" v-for="(item,index) in dataList" :key="index">
			<view class="" slot="head">
				<view class="wrap">
					<u-row>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-2 weikaishi3">
								<span>商品：{{item.goodsName}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-2 weikaishi3">
								<span>入库重量：{{item.putWeight}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
			<view class="" slot="body">
				<view class="wrap">
					<u-row>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-4">
								<span>直发出库重量：</span><span>{{item.zhifaWeight}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-4">
								<span>次果出库重量：</span><span>{{item.ciguoWeight}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-4">
								<span>包装重量：</span><span>{{item.baozhuangWeight}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-4">
								<span>次果库存：</span><span>{{item.ciguoSsWeight}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-4">
								<span>废果库存：</span><span>{{item.feiguoSsWeight}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-4">
								<span>结余：</span><span>{{item.jieyuWeight}}</span>
							</view>
						</u-col>
						<u-col span="12" text-align="left">
							<view class="u-m-t-4 huanhang">
								<span>生产日期：</span><span>{{item.producetime}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
		</u-card>
		<view>
			<u-calendar v-model="show" mode="date" max-date="2070-01-01" @change="change"></u-calendar>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				times:'',
				show:false,
				dataList:[],
			    pageNo: 1,
			    hasMore: true,
			    orderCount: 0,
			}
		},
		onPullDownRefresh() {
			this.refresh()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			uni.showLoading({
				title: '加载中'
			})
			if (this.hasMore) {
				this.pageNo++ 
				setTimeout(() => {
					this.loadOrder({
						times:this.times
					}).then(res => {})
					uni.hideLoading()
				}, 500)
			} else {
				setTimeout(() => {
					uni.hideLoading()
					uni.showToast({
						icon: 'none',
						title: '已经到低了哦',
						duration: 2000
					});
				}, 500)
			}
		},
		onLoad(open) {
			this.refresh()
		},
		methods: {
			getT(){
				this.show = true
			},
			change(e) {
				this.times = e.result
				this.refresh()
			},
			refresh(){
				uni.showLoading({
					title: '加载中...'
				})
				this.pageNo = 1
				this.hasMore = true
				this.loadOrder({
					times:this.times
				}).then(res => {
				})
				uni.hideLoading()
			},
			loadOrder(param = {}) {
				return new Promise((resolve, reject) => {
					param = Object.assign(param, {
						page: this.pageNo,
						limit: 10
					})
					this.$http.post('/rest/fruits/analysislist',{
					},{
						params: param,
						header: {
							'Authorization' :uni.getStorageSync('token'),
						}
					}).then(res => {
						if (this.pageNo == 1) {
							this.dataList = res.data.data
						} else {
							this.dataList = this.dataList.concat(res.data.data)
						}
						this.calculation()
						this.orderCount = res.data.count
						this.hasMore = this.pageNo * 10 < res.data.count
						resolve(res)
					})
				})
			},
			calculation(){
				let newdataList = []
				for(let item of this.dataList) {
					let putWeight = item.putWeight
					if(item.zhifaWeight != null && item.zhifaWeight != ''){
						putWeight = (putWeight-item.zhifaWeight).toFixed(3)
					}
					if(item.ciguoWeight != null && item.ciguoWeight != ''){
						putWeight = (putWeight-item.ciguoWeight).toFixed(3)
					}
					if(item.baozhuangWeight != null && item.baozhuangWeight != ''){
						putWeight = (putWeight-item.baozhuangWeight).toFixed(3)
					}
					if(item.ciguoSsWeight != null && item.ciguoSsWeight != ''){
						putWeight = (putWeight-item.ciguoSsWeight).toFixed(3)
					}
					if(item.feiguoSsWeight != null && item.feiguoSsWeight != ''){
						putWeight = (putWeight-item.feiguoSsWeight).toFixed(3)
					}
					item.jieyuWeight = putWeight;
					newdataList.push(item)
				}
				this.dataList = newdataList
			}
		}
	}
</script>
<style lang="scss">
	page{
			background-color: #ffffff;
	}
	
	.wrap {
		padding: 10rpx;
	}
	.weikaishi2{
		font-size: 36rpx;
	}
	.weikaishi3{
		font-size: 32rpx;
	}
	.huanhang{
		word-break:break-all;
	}
</style>
